(intersection): Keep the elements of the returned list
authorAndreas Schwab <schwab@suse.de>
Sat, 11 May 2002 15:59:49 +0000 (15:59 +0000)
committerAndreas Schwab <schwab@suse.de>
Sat, 11 May 2002 15:59:49 +0000 (15:59 +0000)
in the same order as in the first list.

src/coding.c

index 8c54f86e531618040899cc683a321b6b1d2aea09..baf6acf08af286ba1af8ff15c81c7757f9a041db 100644 (file)
@@ -6324,14 +6324,17 @@ static Lisp_Object
 intersection (l1, l2)
      Lisp_Object l1, l2;
 {
-  Lisp_Object val;
+  Lisp_Object val = Fcons (Qnil, Qnil), tail;
 
-  for (val = Qnil; CONSP (l1); l1 = XCDR (l1))
+  for (tail = val; CONSP (l1); l1 = XCDR (l1))
     {
       if (!NILP (Fmemq (XCAR (l1), l2)))
-       val = Fcons (XCAR (l1), val);
+       {
+         XSETCDR (tail, Fcons (XCAR (l1), Qnil));
+         tail = XCDR (tail);
+       }
     }
-  return val;
+  return XCDR (val);
 }